//
//  FirstViewController.m
//  tradersOnMap
//
//  Created by bilmuh bilmuh on 07.03.2011.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "ProfileViewController.h"

@implementation ProfileViewController

-(void)setup
{
	UIImage *image = [UIImage imageNamed:@"user.png"];
	UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"Profile" image:image tag:0];
	self.tabBarItem = item;
	[item release], [image release];
}

-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
	self = [super initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil];
	if (self) {
		[self setup];
	}
	return self;
}

-(void)awakeFromNib
{
	[self setup];
}

-(void)viewDidLoad
{
	NSUserDefaults *def = [[NSUserDefaults alloc] init];
	NSString *firstName = [def objectForKey:@"firstName"];
	NSString *lastName = [def objectForKey:@"lastName"];
	nameLabel.text = [NSString stringWithFormat:@"%@ %@", firstName, lastName];
	[def release];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSInteger rowCount;
    switch (section) {
        case 0:
            rowCount = 4;
            break;
            
        case 1:
            rowCount = 1;
            break;
    }
    return rowCount;
}

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    NSString *title;
    switch (section) {
        case 0:
            title = [NSString stringWithString:@"Adress"];
            break;
            
        case 1:
            title = [NSString stringWithString:@"Telephone"];
            break;
    }
    return title;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:@"value2"];
	NSString *detailText = [[NSString alloc] init];
	NSString *text = [[NSString alloc] init];
	NSUserDefaults *defaults = [[NSUserDefaults alloc] init];
	
	switch (indexPath.section) {
		case 0:
			switch (indexPath.row) {
				case 0:
					detailText = @"Adress";
					text = [defaults objectForKey:@"adress"];
					break;
				case 1:
					detailText = @"Neighborhood";
					text = [defaults objectForKey:@"neighborhood"];
					break;
				case 2:
					detailText = @"Borough";
					text = [defaults objectForKey:@"borough"];
					break;
				case 3:
					detailText = @"City";
					text = [defaults objectForKey:@"city"];
					break;
			}
			break;
		case 1:
			detailText = @"Phone";
			text = [defaults objectForKey:@"phoneNumber"];
			break;

	}
    cell.detailTextLabel.text = text;
    cell.textLabel.text = detailText;
	[defaults release], [detailText release], [text release];
    return [cell autorelease];
}

@end
